﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.BusinessEntity.DSJCYD94;
using JM.JCY.Proxy;
using System.Linq;
using System.Data;

namespace JM.JCY.SharePointComponent.LawArchives.CitizenCaseDetails
{
    public partial class CitizenCaseDetailsUserControl : UserControl
    {
        T_AJBSGXDataSet.T_AJBSGXDataTable AJBSGXData;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string N_BH = Request.QueryString["N_BH"].ToString();
                this.lbBH.Text = N_BH;
                var MXDT = GetMXDataByBH(Convert.ToDecimal(N_BH));
                BindData(MXDT);
                AJBSGXData = GetAJBSGXDataByBH(Convert.ToDecimal(N_BH));

                lbBATS.Text = AJBSGXData.Count > 0 ? AJBSGXData[0].N_BATS.ToString() : "0";
                DataRow[] DSRRRows = GetMX_DSRByBH(Convert.ToDecimal(N_BH)).Select();
                dlDSR.DataSource = DSRRRows;
                dlDSR.DataBind();
                if (DSRRRows.Count() > 0)
                {

                    DSRNoRecord.Visible = false;
                }

                else
                    DSRNoRecord.Visible = true;

            }
        }
        public T_AJBSGXDataSet.T_AJBSGXDataTable GetAJBSGXDataByBH(decimal BH)
        {
            using (var proxy = new DSJCYD94Proxy())
            {
                return proxy.GetAJBSGXDataByBH(BH);
            }
        }
        public T_MX_AJXXDataSet.T_MX_DSRDataTable GetMX_DSRByBH(decimal BH)
        {
            using (var proxy = new DSJCYD94Proxy())
            {
                return proxy.GetMX_DSRByBH(BH);
            }
        }

        public T_MX_AJXXDataSet.T_MX_AJXXDataTable GetMXDataByBH(decimal BH)
        {
            using (var proxy = new DSJCYD94Proxy())
            {
                return proxy.GetMXInfoByBH(BH);
            }
        }
        public void BindData(T_MX_AJXXDataSet.T_MX_AJXXDataTable MX_AJXX)
        {
            var row = MX_AJXX[0];
            lbID.Text = string.IsNullOrEmpty(row.C_AH) ? string.Empty : row.C_AH.ToString();
            LabelGetDate.Text = row.IsD_SARQNull() ? string.Empty : row.D_SARQ.ToString("yyyy年MM月dd日");
            // 案件来源
            var AJLYDM = GetDMByBXH(701);
            var AJLY = from dm in AJLYDM
                       where !row.IsN_AJLYNull() && dm.N_DM == row.N_AJLY
                       select dm.C_MC;
            lbSource.Text = AJLY.Count() == 0 ? string.Empty : AJLY.First();
            var sSLYDT=GetSSLYInfoByBH(row.N_BH);
            //申诉理由 
            lbReason.Text = sSLYDT.Count > 0 && !sSLYDT[0].IsC_GSNull() ? sSLYDT[0].C_GS : string.Empty;
            lbInvestigateDate.Text = row.IsD_LAQSCRQNull() ? string.Empty : row.D_LAQSCRQ.ToString("yyyy年MM月dd日");
            lbInvestigatePerson.Text = string.IsNullOrEmpty(row.C_SCR) ? string.Empty : row.C_SCR.ToString();
            //立案前审查结论 
            var SCJLDM = GetDMByBXH(716);
            var SCJL = from dm in SCJLDM
                       where !row.IsN_SCJLNull() &&dm.N_DM == row.N_SCJL
                       select dm.C_MC;
            lbResult.Text=SCJL.Count() > 0 ? SCJL.First() : string.Empty;

            lbMark.Text = string.IsNullOrEmpty(row.C_AJBS) ? string.Empty : row.C_AJBS.ToString();
            lbEstablishID.Text = string.IsNullOrEmpty(row.C_SAAH) ? string.Empty : row.C_SAAH.ToString();
            lbEstablishDate.Text = row.IsD_LARQNull() ? string.Empty : row.D_LARQ.ToString("yyyy年MM月dd日");
            //卷宗调齐日期  
            var DJXX=GetDJXXInfoByBH(row.N_BH);
            lbTransferDate.Text = DJXX.Count > 0 && DJXX[0].IsD_DJRQNull() ? DJXX[0].D_DJRQ.ToString("yyyy年MM月dd日") : string.Empty;
            lbClosedDate.Text = row.IsD_JARQNull() ? string.Empty : row.D_JARQ.ToString("yyyy年MM月dd日");
            //审结结果 
            var SCJGDM = GetDMByBXH(707);
            var SCJG = from dm in SCJGDM
                       where !row.IsN_SJJGNull() &&dm.N_DM == row.N_SJJG
                       select dm.C_MC;
            lbClosedResult.Text = SCJG.Count() > 0 ? SCJG.First() : string.Empty;
        }


        //Method to get the data in table T_DM
        public T_DMDataSet.T_DMDataTable GetDMByBXH(decimal BXH)
        {
            using (var proxy = new DSJCYD94Proxy())
            {
                return proxy.GetDMByBXH(BXH);
            }
        }
        public T_MX_AJXXDataSet.T_MX_SSLYDataTable GetSSLYInfoByBH(decimal BH)
        {
            using (var proxy = new DSJCYD94Proxy())
            {
                return proxy.GetSSLYInfoByBH(BH);
            }
        }

        public T_MX_AJXXDataSet.T_MX_DJXXDataTable GetDJXXInfoByBH(decimal BH)
        {
            using (var proxy = new DSJCYD94Proxy())
            {
                return proxy.GetDJXXInfoByBH(BH);
            }
        }

        protected void dlDSR_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            T_MX_AJXXDataSet.T_MX_DSRRow row = (T_MX_AJXXDataSet.T_MX_DSRRow)e.Item.DataItem;
            Label lbName = (Label)e.Item.FindControl("lbName");
            Label lbLitigationPosition = (Label)e.Item.FindControl("lbLitigationPosition");
            lbName.Text = string.IsNullOrEmpty(row.C_XM) ? string.Empty : row.C_XM;
            //诉讼地位  720
            var SSDWDM = GetDMByBXH(720);
            var SSDW = from dm in SSDWDM
                       where !row.IsN_SSDWNull() && dm.N_DM == row.N_SSDW
                       select dm.C_MC;
            lbLitigationPosition.Text = SSDW.Count() > 0 ? SSDW.First() : string.Empty;
        }



    }
}
